//
//  RequestApi.swift
//  yunshang
//
//  Created by zw on 19/05/19.
//  Copyright © 201年 Tommy. All rights reserved.
//

import Foundation
import Moya
import Alamofire
import RxSwift

let YSProvider = MoyaProvider<RequestApi>(plugins:[NetworkMyLoggerPlugin()])

enum RequestCode: String {
    case failError = "0"
    case success = "1"
}

public enum RequestApi {
    //登录
    case login(username: String , password: String)
}

extension RequestApi: TargetType {
    public var headers: [String : String]? {
        ["Device-Type":"iOS"]
    }
    
    public var baseURL: URL {
        return URL.init(string: "http://www.abc.com")!
    }
    
    public var path: String {
        switch self {
        case .login:
            return "/api/user/login"
        }
    }
    
    public var method: Moya.Method {
        return .post
    }
   
    public var task: Task {
        var taskParams : [String : Any]
        switch self {
            //登录
        case let .login(username,password):
            taskParams = ["Username": username,"Password":password]
        }
        return .requestParameters(parameters:taskParams,encoding: JSONEncoding.default)
        
    }
    public var validate: Bool {
        return false
    }
    
    public var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
}




















